package com.futurescale.sa.model.vo
{
	/**
	 * A Cast is a group of characters that appear 
	 * in one or more stories or episodes of a series. 
	 * This value object represents a cast and its 
	 * associated characters. 
	 */
	[Bindable]
	public class CastVO extends ValueObject
	{
		/**
		 * The XML element name.
		 */
		public static const ELEMENT:String = "Cast";
		
		/**
		 * Construct a CastVO.
		 */
		public function CastVO( xml:XML=null )
		{
			super(ELEMENT, xml);
		}
		
		/** 
		 * An name-sorted Vector of a Cast's Characters.
		 */
		public function get characters():Vector.<CharacterVO>
		{
			var v:Vector.<CharacterVO> = new Vector.<CharacterVO>();
			var xl:XMLList = xml..Character;
			for each ( var cx:XML in xl ) {
				var character:CharacterVO = new CharacterVO(cx);
				v.push( character );
			}
			v.sort( ValueObject.nameSort );
			return v;
		}
		public function set characters( v:Vector.<CharacterVO> ):void 
		{} // read-only but bindable		
		
		/**
		 * Add a Character to the Cast.
		 */
		public function addCharacter( character:CharacterVO ):void
		{
			xml.appendChild( character.xml );
		}	
	}
}